from os import read
from sqlite3.dbapi2 import Binary
from pandas.core.frame import DataFrame
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import sqlite3
from GTexamlib.imports import *
import base64

def update_pic(pic_path,year,paper_code,no):
    if no in [331,332,341,342]:
        no-=13
    uuid=str(year)+str(paper_code)+str(no+13)
#"./img/1.png"
#with open("/Users/tylor/GTexam/bek/2020全国1/img/image9.png","rb") as f:
    with open(pic_path,"rb") as f:
        a=base64.b64encode(f.read())
        con = sqlite3.connect("Database.db")
        cur = con.cursor()
        cur.execute('UPDATE single_sel SET figure = (?) WHERE uuid = '+uuid,(a,))
        cur.execute('UPDATE multi_sel SET figure = (?) WHERE uuid = '+uuid,(a,))
        cur.execute('UPDATE essay SET figure = (?) WHERE uuid = '+uuid,(a,))
        con.commit()



if __name__ == '__main__':
    path="./img/1.png"
    path='/Users/tylor/GTexam/bek/2020全国1/img/image15.png'
    update_pic(path,20,1,342)